﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="sys_menu_edit.aspx.cs" Inherits="Ccit.SysPlat.Purview.sys_menu_edit" %>
<%@ Register TagPrefix="ccit" Assembly="Ccit.ServerControls.ActionForm" Namespace="Ccit.ServerControls" %>
<html>
<head runat="server">
    <title></title>
    <script type="text/javascript" src="../script/jQuery.js"></script>
    <script src="../script/StringClass_Ext.js" type="text/javascript"></script>    
    <script src="../script/jsonlib.js" type="text/javascript"></script> 
    <script src="../script/jcontrol.js" type="text/javascript"></script>
    <script type="text/javascript">
    <!--
        function doUpMenuIndexChange() {
            var ctrlUpMenu = new DropDownList("ddlUpMenu");
            $get("_hidAtUpMenuId").value = ctrlUpMenu.selectedValue;
            ctrlUpMenu = null;
        }

        function doCheck() {
            var ctrlMenuName = $get("txtMenuName");
            if (jQuery.trim(ctrlMenuName.value) == "") {
                alert("菜单名称不能为空!");
                ctrlMenuName.focus();
                return false;
            }

            var ctrlOrder = $get("txtOrder");
            var orderNo = jQuery.trim(ctrlOrder.value);
            if ( orderNo != "") {
                if (!orderNo.IsInteger()) {
                    alert("显示顺序只能录入整数!");
                    ctrlOrder.focus();
                    return false;
                }
            }
            return true;
        }

        function doSave(ctrlType) {
            if (!doCheck()) return;

            saveData(ctrlType, "1");
            return false;
        }

        function saveData(ctrlType, checkType) {
            var msMenu = {};
            msMenu.menuId = $get("_hidMenuId").value;
            msMenu.menuName = jQuery.trim($get("txtMenuName").value);
            msMenu.orderNo = jQuery.trim($get("txtOrder").value);
            msMenu.effect = getRadioValue("rdEffect");
            msMenu.showSign = getRadioValue("rdShow");
            msMenu.memo = jQuery.trim($get("txtToolTip").value);
            msMenu.sysSign = "0";
            msMenu.isLeaf = getRadioValue("rdLeaf");
            msMenu.purviewSet = getRadioValue("rdPurview");
            msMenu.pagePath = jQuery.trim($get("txtPagePath").value);
            msMenu.rangeSet = getRadioValue("rdRange");
            msMenu.imgPath = jQuery.trim($get("txtImgPath").value);
            msMenu.menuType = "0";
            msMenu.upMenuId = $get("_hidAtUpMenuId").value;
        
            var vEntryParam = $get("_hidEntryParam").value;
            eval("var msEntryParam=" + vEntryParam);
            var sourceType = msEntryParam.sourceType;
            var formId = msEntryParam.formId;

            msMenu.oriType = sourceType;
            msMenu.formId = formId;

            var jsonExpr = JSON.stringify(msMenu, function(key, value) { return value; });
            PageMethods.SaveMenu(jsonExpr, ctrlType, checkType, ClientCallBack);

            msMenu = null;
            msEntryParam = null;
        }

        function getRadioValue(rdCtrlName) {
            if(rdCtrlName == "" || rdCtrlName == "undefined") return "";
            
            var ctrlRd = new RadioList(rdCtrlName);
            if(null == ctrlRd || ctrlRd == "undefined") return "";
            var chkValue = ctrlRd.checkedValue;
            
            ctrlRd = null;
            return chkValue;        
        }

        function ClientCallBack(vResult) {
            eval("resultObj=" + vResult);
            var vOperType = resultObj.OPERTYPE;
            switch (vOperType) {             
                case "MENUSAVE":  //菜单保存
                    if (parseInt(resultObj.RSTSIGN) > 0) {
                        alert(resultObj.RSTMSG);
                        var isAddNew = ($get("_hidMenuId").value == "") ? "0" : "1";  //是否是新增记录标志  0:是 1:否   
                        var entryParam = $get("_hidEntryParam").value;
                        eval("var msEntryParam=" + entryParam);

                        var menuId = resultObj.RSTSIGN;
                        var msMenu = {};
                        msMenu.menuId = menuId;
                        msMenu.menuName = resultObj.MENUNAME;
                        msMenu.sysSign = resultObj.SYSSIGN;
                        msMenu.isHasChild = resultObj.HASCHILD;
                        msMenu.lay = resultObj.LAY;
                        msMenu.oriType = resultObj.ORITYPE;
                        msMenu.sourceType = msEntryParam.sourceType;
                        var menuExpr = JSON.stringify(msMenu, function(key, value) { return value; });

                        var ctrlType = resultObj.CTRLTYPE;
                        switch (ctrlType) {
                            case "1":
                                $get("_hidMenuId").value = menuId;
                                var ctrlDel = $get("btnDel");
                                ctrlDel.style.visibility = "visible";
                                break;
                            case "2":
                                initAddNew();
                                break;
                        }
                        parent.frames[0].document.getElementById("_hidAtUpMenuId").value = resultObj.UPMENUID; //此处与获取_hidUpDeptId值应一样              
                        parent.frames[0].document.getElementById("_hidOgUpMenuId").value = $get("_hidOgUpMenuId").value;
                        parent.frames[0].document.getElementById("_hidAddNewSign").value = isAddNew;  //新增记录标志
                        parent.frames[0].document.getElementById("_hidCurMenuExpr").value = menuExpr; //当前资产类别对象表达式    
                        parent.frames[0].document.all.btnTrigger.click();
                        $get("_hidOgUpMenuId").value = resultObj.UPMENUID;

                        msMenu = null;
                    }
                    else {
                        var errMsg = resultObj.RSTMSG.replace(/\\r\\n/g, "\r\n");
                        if (resultObj.RSTSIGN == "-990" && confirm(errMsg)) saveData(ctrlType, "0");
                        else alert(errMsg);
                    }
                    break;
                case "MENUDELETE":
                    var delMenuId = resultObj.RSTSIGN;
                    alert(resultObj.RSTMSG);
                    if (parseInt(delMenuId) > 0) {
                        parent.frames[0].document.getElementById("_hidDelMenuId").value = delMenuId;                        
                        parent.frames[0].document.all.btnDelTrigger.click();
                        initAddNew("DELETENEW");
                    }                    
                    break;
            }            
        }

        function initAddNew() {
            $get("_hidMenuId").value = "";
            __doPostBack("lnbCallBack", "");
        }

        function doDelete() {
            if (confirm("删除当前菜单,是否继续?")) {
                var vMenuId = $get("_hidMenuId").value;
                PageMethods.DeleteMenu(vMenuId, ClientCallBack);
            }
            return false;
        }

        function doLeafClick() {
            var vEntryParam = $get("_hidEntryParam").value;
            eval("var msEntryParam=" + vEntryParam);

            if (msEntryParam.sourceType == "0") return;

            var rdLeaf = new RadioList("rdLeaf");
            if (rdLeaf.checkedValue == "0") $get("txtPagePath").value = "";
            else {
                var lstModeId = msEntryParam.lstModeId;
                $get("txtPagePath").value = "CustomGrid/custom_grid_list.aspx?lstModeId=" + lstModeId;
            }

            rdLeaf = null;
            msEntryParam = null;
        }
          
    //-->
    </script> 
</head>
<body scroll="no">
    <ccit:ActionForm id="form1" runat="server">   
    <input type="hidden" id="_hidOgUpMenuId" runat="server" />
    <input type="hidden" id="_hidAtUpMenuId" runat="server" />
    <input type="hidden" id="_hidMenuId" runat="server" />    
    <input type="hidden" id="_hidSysParam" runat="server" />
    <input type="hidden" id="_hidMenuSysType" runat="server" />
    <input type="hidden" id="_hidEntryParam" runat="server" />
    <input type="hidden" id="_hidRecOriType" runat="server" />    
    <asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" runat="server">
    </asp:ScriptManager>
    <table class="tableborder" cellpadding="0" cellspacing="0" width="98%" align="center">
        <tr>
            <td width="10%" class="pformleft" align="right"><nobr>上级菜单</nobr></td>
            <td width="90%" class="pformright" colspan="3">
                <asp:DropDownList ID="ddlUpMenu" CssClass="select" onchange="doUpMenuIndexChange()" Width="99%" runat="server"></asp:DropDownList>
                <%--<dxe:ASPxComboBox ID="cbxUpMenu" DropDownStyle="DropDown" EnableIncrementalFiltering="true" ItemStyle-Height="12px" Width="99%" runat="server">
                    <ClientSideEvents SelectedIndexChanged="function(s, e) { doUpMenuIndexChange(s); }"></ClientSideEvents>                        
                </dxe:ASPxComboBox>--%>
            </td>
        </tr>
        <tr>
            <td width="10%" class="pformleft" align="right"><nobr><font color='red'><b>*</b></font>菜单名称</nobr></td>
            <td width="90%" class="pformright" colspan="3">
                <asp:TextBox ID="txtMenuName" CssClass="input" Width="99%" runat="server"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td width="10%" class="pformleft" align="right"><nobr>菜单顺序</nobr></td>
            <td width="40%" class="pformrightline">
                <nobr>
                    <asp:TextBox ID="txtOrder" CssClass="input" Width="60px" runat="server"></asp:TextBox>
                    &nbsp;<font color="blue" face='Arial' size='1.5'><i><b>注: 为空则由系统默认生成</b></i></font>
                </nobr>                    
            </td>
            <td width="10%" class="pformleft" align="right"><nobr>叶子节点</nobr></td>
            <td width="40%" class="pformright">
                <asp:RadioButtonList ID="rdLeaf" RepeatDirection="Horizontal" onclick="doLeafClick()" runat="server">
                    <asp:ListItem Text="否" Value="0"></asp:ListItem>
                    <asp:ListItem Text="是" Value="1"></asp:ListItem>
                </asp:RadioButtonList>
            </td>
        </tr>
        <tr>                
            <td width="10%" class="pformleft" align="right"><nobr>有效标志</nobr></td>
            <td width="40%" class="pformrightline">
                <asp:RadioButtonList ID="rdEffect" RepeatDirection="Horizontal" runat="server">
                    <asp:ListItem Text="有效" Value="0" Selected="True"></asp:ListItem>
                    <asp:ListItem Text="无效" Value="1"></asp:ListItem>
                </asp:RadioButtonList>
            </td>
            <td width="10%" class="pformleft" align="right"><nobr>显示标志</nobr></td>
            <td width="40%" class="pformright">
                <asp:RadioButtonList ID="rdShow" RepeatDirection="Horizontal" runat="server">
                    <asp:ListItem Text="显示" Value="0" Selected="True"></asp:ListItem>
                    <asp:ListItem Text="不显示" Value="1"></asp:ListItem>
                </asp:RadioButtonList>
            </td>
        </tr>
        <tr>                
            <td width="10%" class="pformleft" align="right"><nobr>权限标志</nobr></td>
            <td width="25%" class="pformrightline">
                <asp:RadioButtonList ID="rdPurview" RepeatDirection="Horizontal" runat="server">
                    <asp:ListItem Text="不需要设置权限" Value="0"></asp:ListItem>
                    <asp:ListItem Text="需要设置权限" Value="1"></asp:ListItem>
                </asp:RadioButtonList>
            </td>
            <td width="10%" class="pformleft" align="right"><nobr>范围标志</nobr></td>
            <td width="25%" class="pformright">
                <asp:RadioButtonList ID="rdRange" RepeatDirection="Horizontal" runat="server">
                    <asp:ListItem Text="不需要设定范围" Value="0"></asp:ListItem>
                    <asp:ListItem Text="需要设定范围" Value="1"></asp:ListItem>
                </asp:RadioButtonList>
            </td>
        </tr>
        <tr>
            <td width="10%" class="pformleft" align="right"><nobr>页面路径</nobr></td>
            <td width="90%" class="pformright" colspan="5">
                <asp:TextBox ID="txtPagePath" CssClass="input" Width="99%" runat="server"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td width="10%" class="pformleft" align="right"><nobr>图片路径</nobr></td>
            <td width="90%" class="pformright" colspan="5">
                <asp:TextBox ID="txtImgPath" CssClass="input" Width="99%" runat="server"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td width="10%" class="pformleft" align="right"><nobr>菜单提示</nobr></td>
            <td width="90%" class="pformright" colspan="5">
                <asp:TextBox ID="txtToolTip" CssClass="input" Width="99%" runat="server"></asp:TextBox>
            </td>
        </tr>
        <tr class="pformstrip">
            <td colspan="6" align="center">
                <input type="button" id="btnSave" class="button" value="保存" onclick="doSave('1')" /> 
                <%--<asp:Button ID="btnSave" CssClass="button" Text="保存" runat="server" />--%>
                &nbsp;
                <input type="button" id="btnSaveConti" class="button" value="保存并新增" onclick="doSave('2')" />
                <%--<asp:Button ID="btnSaveAdd" CssClass="button" Text="保存并新增" runat="server" />--%>
                &nbsp;
                <input type="button" id="btnDel" class="button" value="删除" onclick="doDelete()" />
                <%--<asp:Button ID="btnDel" CssClass="button" Text="删除" runat="server" />--%>
            </td>
        </tr>
    </table>
    <asp:LinkButton ID="lnbCallBack" runat="server" style="display:none" onclick="lnbCallBack_Click"></asp:LinkButton>
    </ccit:ActionForm>
    <script type="text/javascript">
    <!--
        $(document).ready(function() {
            var menuId = $get("_hidMenuId").value;
            var sysParam = $get("_hidSysParam").value;
            var menuSysType = $get("_hidMenuSysType").value;
            var ctrlSave = $get("btnSave");
            var ctrlSaveConti = $get("btnSaveConti");
            var ctrlDel = $get("btnDel");

            var nodeRecOri = $get("_hidRecOriType").value;
            eval("var msEntryParam=" + $get("_hidEntryParam").value);
            var sourceType = msEntryParam.sourceType;
            if ((sysParam != "999" && menuSysType == "1") || (nodeRecOri != "" && (nodeRecOri != sourceType))) {
                ctrlSave.disabled = "disabled";
                ctrlSaveConti.disabled = "disabled";
                ctrlDel.disabled = "disabled";
            }
            
            if (menuId == "")
                ctrlDel.style.visibility = "hidden";
            else
                ctrlDel.style.visibility = "visible";

            msEntryParam = null;

            //由父页面的入口参数重新配置当前页面的入口参数
            $get("_hidEntryParam").value = parent.$get("_hidEntryParam").value;
        });
    //-->
    </script>
</body>
</html>
